import ArrayUtil from '@/ArrayUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 进食
 **/
export default class BossSpell_HydraEat extends AbilityBase {
    static instance: BossSpell_HydraEat;
    constructor(id: string = 'Ajt2') {
        super(id);
        BossSpell_HydraEat.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('进食', source);
        target = SelectUtil.getRandomEnemyInRange(source, 1000);
        let x = GetUnitX(source);
        let y = GetUnitY(source);
        let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, x, y);
        MovementCommon.定点投射物({
            missile: 'Abilities\\Weapons\\SludgeMissile\\SludgeMissile.mdl',
            caster: source,
            speed: 500,
            radian: 0.5,
            tarX: x,
            tarY: y,
            other: mark,
            onReachTarget: this.onMissileReachTarget.bind(this),
        });
    }
    onMissileReachTarget(p: 定点投射物参数) {
        DestroyEffect(p.other);
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 175, p.curX, p.curY);
        let target = ArrayUtil.randomElement(es);
        if (target == null) return;
        DamageSystemInstance.applyIceDamage(target, p.caster, 2000);
        let distance = MathUtil.distanceBetweenPoints(p.curX, p.curY, GetUnitX(p.caster), GetUnitY(p.caster));
        let angle = MathUtil.angleBetweenCoords(p.curX, p.curY, GetUnitX(p.caster), GetUnitY(p.caster));
        MovementCommon.hitFly({
            target,
            distance,
            time: 0.75,
            maxHeight: 400,
            angle,
            caster: p.caster,
            onEnd: this.onSkillEnd.bind(this),
        });
    }
    onSkillEnd(p: HitFlyConfig) {
        DestroyEffect(AddSpecialEffect('atswx (13).mdx', GetUnitX(p.target), GetUnitY(p.target)));
        DamageSystemInstance.applyLightingDamage(p.target, p.caster, 2000);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
